package cn.apelx.api.store.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

/**
 * 仓库dubbo接口
 *
 * @author apelx
 * @since 2022-05-01
 */
@LocalTCC
public interface StoreDubboService {

    /**
     * 减库存
     *
     * @param storeId
     * @param subNum
     */
    void subStore(String storeId, BigDecimal subNum);


    /**
     * 减库存
     *
     * @param actionContext tcc事务业务上下文
     * @param storeId
     * @param subNum
     */
    @TwoPhaseBusinessAction(name = "subStoreTcc", commitMethod = "subStoreTccCommit", rollbackMethod = "subStoreTccRollback")
    void subStoreTcc(BusinessActionContext actionContext,
                     @BusinessActionContextParameter(paramName = "storeId") String storeId,
                     @BusinessActionContextParameter(paramName = "subNum") BigDecimal subNum);

    void subStoreTccCommit(BusinessActionContext actionContext);

    void subStoreTccRollback(BusinessActionContext actionContext);

    /**
     * 测试调用链路集成到zipkin
     *
     * @return
     */
    String getStore();
}
